package cn.lger.icollege.util;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;


/**
 * Code that Changed the World
 * Pro said
 * Created by Pro on 2018-04-21.
 */
public class PageableGenerator {

    /**
     * 根据当前页和页面大小生成pageable，默认currentPage=0，pageSize=5
     * @param currentPage currentPage
     * @param pageSize pageSize
     * @return Pageable
     */
    public static Pageable pageOf(Integer currentPage, Integer pageSize){
        if (currentPage == null || currentPage == 0){
            currentPage = 0;
        }
        if (pageSize == null || pageSize == 0){
            pageSize = 5;
        }
        return PageRequest.of(currentPage, pageSize);
    }

    public static Pageable pageOf(Integer currentPage, Integer pageSize, Sort sort){
        if (currentPage == null || currentPage == 0){
            currentPage = 0;
        }
        if (pageSize == null || pageSize == 0){
            pageSize = 5;
        }
        return PageRequest.of(currentPage, pageSize, sort);
    }

}
